package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ghy
 * @version 1.0.1
 * @date 2023-04-20 12:10:28
 */
@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品相关接口")
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 套餐起售停售
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("菜品起售停售")
    public Result startOrStop(@PathVariable Integer status, Long id) {
        return dishService.startOrStop(status, id);
    }

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    public Result<List<Dish>> list(Long categoryId){
        return dishService.list(categoryId);
    }

    @ApiOperation("修改菜品")
    @PutMapping
    public Result findById(@RequestBody DishDTO dishDTO){
        log.warn("{}", dishDTO);
        return dishService.update(dishDTO);
    }

    @ApiOperation("根据ID查询菜品")
    @GetMapping("/{id}")
    public Result<DishVO> findById(@PathVariable(name = "id") Long id){
        log.warn("{}", id);
        return dishService.findById(id);
    }


    @ApiOperation("批量删除菜品")
    @DeleteMapping
    public Result deleteByIds(@RequestParam(name = "ids") List<Long> ids){
        log.warn("{}", ids);
        return dishService.deleteByIds(ids);
    }

    @ApiOperation("菜品分页条件查询")
    @GetMapping("/page")
    public Result<PageResult> pageQuery(DishPageQueryDTO dishPageQueryDTO){
        log.warn("{}", dishPageQueryDTO);
        return dishService.pageQuery(dishPageQueryDTO);
    }


    @ApiOperation("新增菜品")
    @PostMapping
    public Result add(@RequestBody DishDTO dishDTO){
        log.warn("{}", dishDTO);
        return dishService.add(dishDTO);
    }

}
